import re
import requests
import os
main_ip = "https://www.sanchuangedu.cn"
sc = requests.get(main_ip)
save_address = "E:\\xsfhteacher\\img\\"
address = re.findall(r"(?<=img src=\").+(?=\" a)",sc.text)
with open("img.txt","w+") as img_address:
    for line in address:
        path = main_ip + line
        img_address.write(f"{path}\n")
fp = open("img.txt","r")
try:
    if not os.path.exists(save_address):
        os.mkdir(save_address)
    fp = open("img.txt", "r")
    for line in fp.read().splitlines():
        picture_name = line.split('/')[-1]
        r = requests.get(line)
        if not os.path.exists(save_address+picture_name):
            with open(save_address+picture_name,'wb') as f:
                f.write(r.content)
        else:
            print("the img has download before")
except:
    print("file is existence,please cotinue")






